<template>
	<view class="nav-box" :style="{'height':height+'px','background':bgColor}">
		<!-- 自定义导航栏 -->
		<view class="status_bar" :style="{'height':statusBarHeight+'px'}">
			<!-- uni-ui这里是状态栏 -->
		</view>
		<!-- 胶囊位置信息 -->
		<view class="nav-main flex align-center justify-center" style="disply:flex"
			:style="{height: navBarHeight+'px',lineHeight:navBarHeight+'px',background:bgColor2}">
			<view class="nav-main-back" @click="back" v-if="backIcon">
				<uni-icons type="back" size="22" :color="backColor" :style="{position:is_relative?'relative':'none'}"></uni-icons>
			</view>
			<view v-if="backIcon" style="justify-content:center;width: 444rpx;display: flex;">
				<text :style="{position:is_relative?'relative':'none'}"	class="nav-main-title">{{title}}</text>
			</view>
			<view v-else style="justify-content:center;display: flex;">
				<text :style="{position:is_relative?'relative':'none'}"	class="nav-main-title">{{title}}</text>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		props: {
			bgColor: {
				type: String,
				// default: "#F5F5F5",
				default:""
			},
			bgColor2: {
				type: String,
				// default: "#F5F5F5",
				default:""
			},
			backColor: {
				type: String,
				// default: "#F5F5F5",
				default:"#000000"
			},
			backIcon: {
				type: Boolean,
				default: true
			},
			title: {
				type: String,
				default: "我的"
			},
			is_relative:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				//总高度
				height: 0,
				//胶囊位置信息
				menuButtonRect: {},
				//状态栏的高度
				statusBarHeight: 0,
				//导航栏的高度
				navBarHeight: 0,
				titleWidth:444
			}
		},
		created() {
			this.getHeight();
		},
		methods: {
			//获取屏幕导航栏高度
			getHeight() {
				let sysInfo = uni.getSystemInfoSync(); //状态栏的高度
				this.statusBarHeight = sysInfo.statusBarHeight;
				// 胶囊位置信息
				let rect = uni.getMenuButtonBoundingClientRect();
				this.menuButtonRect = JSON.parse(JSON.stringify(rect));
				// 导航栏高度
				let navBarHeight = (rect.top - sysInfo.statusBarHeight) * 2 + rect.height;
				this.navBarHeight = navBarHeight;
				this.titleWidth = sysInfo.screenWidth*2;
				// 自定义导航栏的高度
				this.height = sysInfo.statusBarHeight + navBarHeight;

			},
			//返回
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.status_bar {
		// height: var(--status-bar-height);
		width: 100%;
		
	}

	.nav-main {

		background:#FFFFFF;
		.nav-main-back {
			width: 120rpx;
			float: left;
			margin-left: 20rpx;
		}

		.nav-main-title {
			color: #000000;
			font-size: 16px;
		}
	}
</style>